$(function() {

  function zerofill(n) {
    return n < 10 ? '0' + n : n;
  }

  $.ajax({
    url: '/qfang-weixin/qiye/meeting/myMeeting',
    data: {
      mobile: $.config.mobile,
      type: 'YES'
    },
    beforeSend: function() {
      $.showPreloader();
    },

    success: function(data) {
      if (data.code == '1000') {
        var html = '';
        var items = data.data.items;
        var meetingLength = items.length;

        if (meetingLength) {
          $('#meetingLength').removeClass('dn').find('span.number-meeting').text(meetingLength);
          $.each(items, function(k, v) {
            var newDate = new Date(v.date);
            var timeText = null;
            var startTime = v.dates.split(',')[0].split('-')[0];

            html += '<li>' +
              '<div class="row">' +
              '<span class="col-40 field-name">会议主题:</span>' +
              '<span><b>' + (v.title ? v.title : '') + '</b></span>' +
              '</div>' +
              '<div class="row">' +
              '<span class="col-40 field-name">会议开始时间:</span>' +
              '<span class="time">' + zerofill((newDate.getMonth() + 1)) + ' 月' + zerofill(newDate.getDate()) + ' 日 ' + startTime + ':00</span>' +
              '</div>' +
              '<div class="row">' +
              '<span class="col-40 field-name">会议时长:</span>' +
              '<span>' + v.dates.split(',').length + '小时</span>' +
              '</div>' +
              '<div class="row">' +
              '<span class="col-40 field-name">会议地点:</span>' +
              '<span>' + v.storey + '楼 ' + v.conferenceName + '</span>' +
              '</div>' +
              '</li>';
          });

          $('.no-data').addClass('dn');
          $('#launchMeeting').empty().append(html);
        } else {
          $('.no-data').removeClass('dn');
          $('#bookingList').empty();
        }
      } else {
        $.toast(data.msg);
      }
    },

    complete: function() {
      $.hidePreloader();
    }
  });
});
